import 'package:bloc/bloc.dart';

import 'demo_event.dart';
import 'demo_state.dart';

class DemoBloc extends Bloc<DemoEvent, DemoState> {
  DemoBloc() : super(DemoState().init());
  @override
  Stream<DemoState> mapEventToState(DemoEvent event) async* {
    if (event is ChangeQuantityEvent) {
      yield* _ChangeQuantityToState(event);
    }
  }

  ///切换模式
  Stream<DemoState> _ChangeQuantityToState(ChangeQuantityEvent event) async* {
    yield state.clone()..num = event.num;
  }
}
